
<!DOCTYPE HTML>
<html>
<head>
<title>招聘者主页</title>
<link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
<!-- jQuery (necessary JavaScript plugins) -->
<script src="js/jquery.min.js"></script>
<!-- Custom Theme files -->
<link href="css/dashboard.css" rel="stylesheet">
<link href="css/style2.css" rel='stylesheet' type='text/css' />
<link href="css/style.css" rel='stylesheet' type='text/css' />
<link href="css/popuo-box.css" rel="stylesheet" type="text/css"
		media="all" /> 
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="application/x-javascript">
	
	 addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } 

</script>

<script type="text/javascript" src="js/move-top.js"></script>
<script type="text/javascript" src="js/easing.js"></script>

<style>
#win {
	position: fixed;
	top: 20%;
	left: 20%;
	 
	width: 60%;
	min-width: 200px;
	min-height: 200px;
	height: 400px;
	background: #fff;
	border: 4px solid #f90;
	//margin: -102px 0 0 -202px;
	display: none;
	z-index: 2;
	overflow-y:auto;
}

#closeScroll {
	font-size: 20px;
	text-align: right;
	background: #FC0;
	border-bottom: 3px solid #f90;
	padding: 5px;
}

#close {
	color: #f90;
	cursor: pointer;
	background: #fff;
	border: 1px solid #f90;
	padding: 0 2px;
	padding: 0 6px;
}

#popTitle,#addTitle {
	margin: 10px;
	padding: 5px;
}

#popContent,#addContent,#addType,#popType,#popNum {
	margin: 10px;
	padding: 5px;
}

#addPersonNum {
	margin: 10px;
	width: 50px;
}

.add {
	margin: 10px;
}

#addType {
	display: inline-block;
	width: 200px;
}

#add {
	display: none;
}

.border {
	border-bottom: 3px dashed grey;
	margin: 10px;
	padding: 10px;
	min-height: 10px;
}

#popContent {
	/* display:block;
	height:100px;
	overflow-y :  auto ; */
	
}

.button0{
	margin:10px;
}

.details > *,#eIntro{
	margin:10px;
}

.company_details:hover{
	background: #e3e3e3;
	cursor:pointer;
}

</style>

</head>
<body>
	<div class="header" id="home">
		<div class="container">
			<div class="head">
				<div class="logo">
					<a href="index.html"><img src="images/logo.png" alt="" /></a>
				</div>
				<div class="navigation">
					<span class="menu"></span>
					<ul class="navig">
						<li><a href="#" id="logoff" class="hvr-bounce-to-bottom">注销</a></li>
						<li><a href="recuitFile.html"
							class="active hvr-bounce-to-bottom">招聘者个人主页</a></li>
						<li><a href="recuitFile3.html" class="hvr-bounce-to-bottom">职位列表</a></li>
						<li><a href="contact.html" class="hvr-bounce-to-bottom">contact</a></li>
					</ul>
				</div>
				<div class="clearfix"></div>
			</div>
		</div>
	</div>

	<!-- header -->
	<div class="col-sm-3 col-md-2 sidebar">
 
		<div class="details">
			<h1 id="eName"></h1>
			<h4 >账号 <span id="eAccount"></span></h4>

			<h4>电话   <span id="eTel" contenteditable="true"></span></h4>
			<h4  >简介</h4>
			<p id="eIntro" contenteditable="true"></p>
		</div>
		<div class="clearfix"></div>
	</div>
 
	<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
		<div class="content">
			<div class="company">
				<h3 class="clr1">已发布招聘信息</h3>

			</div>
			<div class="company" id="elist"></div>
			<div id="win">
				<h2 id="closeScroll">
					<span id="close">x</span>
				</h2>
				<button type="button" class="btn btn-primary" id="modify">修改</button>
				<button type="button" class="btn btn-success" id="modiSubmit">提交</button>
				<button type="button" class="btn btn-success" id="deal">处理</button>
				<button type="button" class="btn btn-success" id="delete">删除</button>
				
				<p class="border">
					标题： <span id="popTitle"></span>
				</p>
				<p class="border">
					人数： <span id="popCurrentNum"></span>/<span id="popRequestNum"></span>
				</p>

				<p class="border">
					类型： <span id="popType"></span>
				</p>
				<div class="border">
					<span>详情：</span>  
					<div id="popContent">
					</div>
				</div>
			</div>
		 	<button type="button" class="btn btn-primary button0" id="addMessage">发布新的招聘信息</button>
			
			<div id="add">
				<h2 id="addTitle" contenteditable="true">title</h2>
				<h4 id="addContent" contenteditable="true">content</h4>
				<span class="add">人数：</span> <input value="10" type="number"
					id="addPersonNum"> <br> <span class="add">职位类型：</span>
				<span id="addType" contenteditable="true">input type</span><br>
				<button type="button" class="btn btn-primary button0" id="submitMessage">提交发布</button>
				<button type="button" class="btn btn-primary button0" id="cancelSubmit">取消发布</button>

			</div>

		</div>


	</div>
	</div>
	<a href="#home" id="toTop" class="scroll" style="display: block;">
		<span id="toTopHover" style="opacity: 1;"> </span>
	</a>
	<script type="text/javascript" src="js/Common.js"></script>

	<script>
		var elist = document.getElementById("elist"), title, elistId;
		var oClose = document.getElementById("close");
		var oWin = document.getElementById("win");

		$(function() {
			updateList();

			$("#addType").css("border", "solid 1px grey");
			$("#addTitle").css("border", "solid 1px grey");
			$("#addContent").css("border", "solid 1px grey");

		})
		//发布新的招聘信息事件
		$("#addMessage").click(function() {
			$("#add").css("display", "block");
			$("#addTitle").html("title");
			$("#addContent").html("content");
			$("#addType").html("input type");
			$("#addPersonNum").val("10");
		});
		//取消发布新的招聘信息事件
		$("#cancelSubmit").click(function() {
			$("#add").css("display", "none");
		});

		//提交发布
		$("#submitMessage").click(function() {
			var ob = {};

			ob.eTitle = $("#addTitle").html();
			
			 
 			ob.eListIntro =transcode($("#addContent").html()) ;
			 
 			ob.ePersonNum = $("#addPersonNum").val();
			ob.eClass = $("#addType").html();
			console.log(ob.eListIntro);

			ajax("POST", "elist.publish.do", ob, function(data) {
				console.log(data);
				var data = JSON.parse(data);
				showMessage("发布成功", function() {
					$("#add").css("display", "none");
					updateList();

				});

			}, function() {
				showMessage("提交失败");
			});

			//ajax succ

		});

		//点击修改按钮
		$("#modify").click(function() {

			$("#modiSubmit").css("display", "inline");
			$("#modify").css("display", "none");
			$("#deal").css("display", "none");
			$("#delete").css("display", "none");

			$("#popTitle").attr("contenteditable", "true");
			$("#popContent").attr("contenteditable", "true");
			$("#popRequestNum").attr("contenteditable", "true");
			$("#popType").attr("contenteditable", "true");

			$("#popTitle").css("border", "solid thin black");
			$("#popContent").css("border", "solid thin black");
			$("#popRequestNum").css("border", "solid thin black");
			$("#popType").css("border", "solid thin black");
		});

		//点击提交按钮
		$("#modiSubmit").click(function() {
			if ($("#popTitle").attr("contenteditable") === "true") {

				var ob = {};
				ob.eTitle = $("#popTitle").html();
				 
				ob.eListIntro =transcode( $("#popContent").html());
				ob.elistId = $("#popContent").data("id");
				ob.ePersonNum = $("#popRequestNum").html();
				ob.eClass = $("#popType").html();
				console.log(ob.elistId + ob.eTitle + ob.eListIntro);

				ajax("POST", "elist.change.do", ob, function(data) {
					console.log(data);
					var data = JSON.parse(data);
					oClose.onclick();

					showMessage("修改成功", function() {
						updateList();
					});

				}, function() {
					showMessage("提交失败");
				});

			} else {
				showMessage("请先修改");
			}

		});

		//点击处理按钮
		$("#deal").click(function() {

			window.location.href = "recuitFile2.html";
		});

		//点击删除按钮
		$("#delete").click(function() {
			if (!confirm("是否确认")) {
				return;
			}
			var ob = {};
			ob.elistId = $("#popContent").data("id");
			console.log(ob.elistId);

			ajax("POST", "elist.remove.do", ob, function(data) {
				console.log(data);
				var data = JSON.parse(data);

				showMessage("删除成功", function() {
					oClose.onclick();
					updateList();
				});
			}, function() {
				showMessage("删除失败");
			});
		});

		oClose.onclick = function() {
			$("#popTitle").html("");
			$("#popContent").html("");
			$("#popRequestNum").html("");
			$("#popCurrentNum").html("");
			$("#popType").html("");
			 

			oWin.style.display = "none";
			$("#popTitle").attr("contenteditable", "false");
			$("#popContent").attr("contenteditable", "false");
			$("#popRequestNum").attr("contenteditable", "false");
			$("#popType").attr("contenteditable", "false");

			$("#popTitle").css("border", "solid 0px grey");
			$("#popContent").css("border", "solid 0px grey");
			$("#popRequestNum").css("border", "solid 0px grey");
			$("#popType").css("border", "solid 0px grey");
		}

		function oriButton() {
			$("#modiSubmit").css("display", "none");
			$("#modify").css("display", "inline");
			$("#deal").css("display", "inline");
			$("#delete").css("display", "inline");
		}

		//更新招聘信息列
		function updateList() {

			oriButton();
			elist.innerHTML = "";
			ajax("POST", "elist.alrPublish.do", {}, function(data) {
				var data = JSON.parse(data);
				title = data.eTitle;
				elistId = data.elistId
				if (!title) {
					return;
				}
				for (var i = 0; i < title.length; i++) {
					createList(title[i], elistId[i]);
				}
			});
		}
		function createList(title, id) {
			var div = document.createElement("div"), p = document
					.createElement("p");

			p.innerHTML = "" + title;

			p.className = "cmpny1";
			div.className = "company_details";
			div.appendChild(p);

			//详情点击事件
			div.onclick = function() {
				oriButton();
				$("#cancelSubmit").click();
				
				console.log(id);
				localStorage.elistId = id;
				localStorage.title = title;
				oWin.style.display = "block";
				$("#popTitle").html(title);

				var content = "";

				ajax("POST", "elist.detail.do", {
					elistId : id
				}, function(msg) {
					console.log(msg);
					var data = JSON.parse(msg);
					console.log(data.eListIntro);
					$("#popContent").html(data.eListIntro);
					$("#popContent").data("id", id);
					$("#popType").html(data.eClass);
					$("#popRequestNum").html(data.ePersonNum);
					$("#popCurrentNum").html(data.num);

				}, function() {
					$("#popContent").html("无法获取详情");
				});
			}
			elist.appendChild(div);
		}
		//提交个人信息
		function submitMessage(id) {

			var idName = "#" + id;

			var element = $(idName), elementBuffer;

			element.focus(function() {
				console.log("d");
				eAccountBuffer = element.html();
			})
			element.blur(function() {

				if (eAccountBuffer !== element.html()) {

					var ob = {};
					ob.eTel = $("#eTel").html();
					ob.eIntro = $("#eIntro").html();

					ajax("POST", "employee.update.do", ob, function(data) {
						console.log(data);
						var data = JSON.parse(data);
						if (data.judge) {
							showMessage("修改成功");
						} else {
							showMessage("修改失败");
						}

					});
				}
			});
		}

		submitMessage("eTel");
		submitMessage("eIntro");

		jQuery(document).ready(function($) {
			$(".scroll").click(function(event) {
				event.preventDefault();
				$('html,body').animate({
					scrollTop : $(this.hash).offset().top
				}, 1000);
			});
		});
		$("span.menu").click(function() {
			$(" ul.navig").slideToggle("slow", function() {
			});
		});

		(function() {

			$(updateInformation);

			function updateInformation() {
				ajax("POST", "employee.get.do", {}, function(data) {
					console.log(data);
					var data = JSON.parse(data);
					if (data.judge === false) {
						showMessage("请先登录", function() {
							window.location.href = "index.html";
						});
					}
					setInformation("eAccount", data);
					setInformation("eTel", data);
					setInformation("eName", data);
					setInformation("eIntro", data);

				});
			}

			function setInformation(id, data) {
				var idName = "#" + id, element = $(idName);
				console.log(" " + data[id]);
				element.html(data[id] + '');
			}

			function submitMessage(id) {

				var idName = "#" + id;

				var element = $(idName), elementBuffer;

				element.focus(function() {
					eAccountBuffer = element.html();
				})
				element.blur(function() {

					if (eAccountBuffer !== element.html()) {

						var ob = {};
						ob[id] = element.html();
						console.log(ob);
						//succ or fail
						updateInformation();
					}
				});
			}

			submitMessage("sMajor");
			submitMessage("sCollege");
			submitMessage("sGrade");
			submitMessage("sTel");
			submitMessage("selfIntro");
		})();
	</script>

</body>
</html>